package com.keyinong.parkin.home.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.example.parkin.R;
import com.keyinong.parkin.home.bean.AddressBean;
import com.keyinong.parkin.home.bean.ParkinBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SelectAddressAdapter extends BaseAdapter {
	Context context;
	HashMap<String, ArrayList<ParkinBean>> maplist;
	ArrayList<AddressBean> addlist;
	ListView listview;
	int isindex = 0;

	public SelectAddressAdapter(Context context,
			ArrayList<AddressBean> addlist, ListView listview) {
		super();
		this.context = context;
		this.addlist = addlist;
		this.listview = listview;
	}

	public void getindex(int isindex) {
		this.isindex = isindex;
	}

	@Override
	public int getCount() {

		return addlist.size();
	}

	@Override
	public Object getItem(int position) {

		return addlist.get(position);
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHandle handle = null;
		if (view == null) {
			handle = new ViewHandle();
			view = LayoutInflater.from(context).inflate(
					R.layout.item_pplist_carlist, null);
			handle.tv_car = (TextView) view.findViewById(R.id.tv_car);
			view.setTag(handle);
		} else {
			handle = (ViewHandle) view.getTag();
			
		}
		if(isindex == position){
			handle.tv_car.setTextColor(context.getResources().getColor(
					R.color.homeBlue));
		}else{
			handle.tv_car.setTextColor(context.getResources().getColor(
					R.color.timeGray));
		}
		handle.tv_car.setText(addlist.get(position).getCity());

		return view;
	}

	private class ViewHandle {
		TextView tv_car;
	}
}
